<?php

namespace app\api\controller\v1;

use app\admin\model\Problemlist;

class Problem extends Base
{
    protected $pageSize = 1;
    public function proList()
    {

        $page                   = $this->params['page'] ?? 1;
        $type                   = !empty($this->params['type']) ? $this->params['type'] : 4;//1必读 2 NEW 3 HOT

        switch ($type)
        {
            case 1:
                $fk_bdl_label = 0;
                break;
            case 2:
                $fk_bdl_label = 1;
                break;
            case 3:
                $fk_bdl_label = 2;
                break;
            case 4:
                $fk_bdl_label = 4;
                break;
        }

        $data = Problemlist::where('fenable', 1)
            ->where('forgid','in', $this->forgids)
            ->where('fk_bdl_bd_datacenter', $this->datacenter)
            ->order('fk_bdl_weight', 'asc');
        if($fk_bdl_label !== 4)
        {
            $data->where('fk_bdl_label','like', "%{$fk_bdl_label}%");
        }

            $data = $data->select();

        $this->success('',$data);
    }

    public function content()
    {
        $check      = $this->plulicValidate($this->params,
            ['id|Id'],
            ['require',  'require']);

        if ($check['code'] == 1)
        {
            $this->error($check['msg']);
        }
        $data   = Problemlist::get($this->params['id']);

        Problemlist::where('id',$this->params['id'])->setInc('fk_bdl_pageview');

        $this->success('',$data);
    }
}